/* Copyright (c) 2002-2009 Grupo e-Gen.  All rights reserved.
 *
 * ====================================================================
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * either version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 * 
 */
 
package consultoria.exercicio.principal;

import java.util.ArrayList;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 * Class: VeiculoContentProvider
 *   
 * @author Grupo e-Gen 
 * @version 4.1 (24/06/2009)
 * @since 4.1 (24/06/2009)
 */
public class VeiculoContentProvider implements IStructuredContentProvider {

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		
	}

	@Override
	public Object[] getElements(Object inputElement) {
		ArrayList<Veiculo> veicAux = null;

		if(inputElement instanceof Veiculo[]){
			Veiculo[] veic = (Veiculo[]) inputElement;
			veicAux = new ArrayList<Veiculo>();
			
			for (int i = 0; i < veic.length; i++){
				if(veic[i].getTipo().equals("Aquatico")){
					veicAux.add(veic[i]);
				}
			}
			for (int i = 0; i < veic.length; i++){
				if(veic[i].getTipo().equals("Terrestre")){
					veicAux.add(veic[i]);
				}
			}
			for (int i = 0; i < veic.length; i++){
				if(veic[i].getTipo().equals("Aereo")){
					veicAux.add(veic[i]);
				}
			}
		}
		
		return (Object[])veicAux.toArray();
	}
}
